package com.dao.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import net.sf.json.JSONObject;

import org.apache.log4j.Logger;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Component;

import com.bean.UserBind;
import com.dao.UserBindDao;
import com.util.DateUtil;
import com.util.LoggerUtil;

@Component
public class UserBindDaoImpl implements UserBindDao{

	public static Logger logger=Logger.getLogger(UserBindDaoImpl.class);
	@Autowired
	private MongoTemplate mongoTemplate;

	@Override
	public Map<String, Object> insertUserBind(String mId, String wId,
			String gender, String mobile,String lId,String type,Integer age,String name, JSONObject logs) {
		Map<String, Object> map=new HashMap<>();
		try {
			UserBind userBind=new UserBind(new ObjectId(mId), wId, gender, mobile,new ObjectId(lId),type,age,name,DateUtil.formatDateToStrAll(new Date()));
			mongoTemplate.insert(userBind);
			map.put("code", "0");
			LoggerUtil.backlogsSuccess(logs, logger);
		}catch (Exception e) {
			e.printStackTrace();
			map.put("code", "101");
			LoggerUtil.backlogsFalseError(logs, logger,e);
			return map;
		}
		return map;
	}
	
	
}
